package com.easefun.polyv.liveecommerce.scenes.fragments.widget;

import android.content.Context;
import android.net.http.SslError;
import android.view.View;
import android.webkit.SslErrorHandler;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.easefun.polyv.R;
import com.lxj.xpopup.core.BottomPopupView;

import org.jetbrains.annotations.NotNull;

/**
 * date: 2023-07-06
 * author: zhy
 * description: 直播介绍
 */
public class PLVDescDialogView extends BottomPopupView {
    // <editor-fold defaultstate="collapsed" desc="变量">
    //功能列表
    private WebView wvContent;
    //关闭按钮
    private ImageView plvIvPointRewardClose;
    private String content;
    private Context mContext;

    public PLVDescDialogView(@NonNull @NotNull Context context, String content) {
        super(context);
        this.mContext = context;
        this.content = content;
    }

    // </editor-fold >

    @Override
    protected int getImplLayoutId() {
        return R.layout.plv_desc_dialog;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        wvContent = findViewById(R.id.wvContent);
        initWebView();
        wvContent.loadUrl("https://www.baidu.com");
        plvIvPointRewardClose = findViewById(R.id.plv_iv_point_reward_close);
        plvIvPointRewardClose.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

    private void initWebView() {
        WebSettings settings = wvContent.getSettings();
//        settings.setUseWideViewPort(true);
//        settings.setLoadWithOverviewMode(true);
//        settings.setSupportZoom(true);
//        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
//        settings.setDisplayZoomControls(false);
        settings.setJavaScriptEnabled(true);
//        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        wvContent.setWebViewClient(new WebViewClient(){
            @Override
            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                super.onReceivedSslError(view, handler, error);
                handler.proceed();
            }
        });
    }

}
